<HTML><HEAD>
<!--
    ---------
    DICE Game
    ---------
-->

<SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers

/*
    THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com
    Copyright (c)2000 by Charles River Media.  All Rights Reserved.
    
    This applet can only be re-used or modifed by license holders of the
    JavaScript Cookbook CD-ROM.  Credit must be given in the source
    code and this copyright notice must be maintained. If you do
    not hold a license to the JavaScript Cookbook, you may NOT
    duplicate or modify this code for your own use.

    Use at your own risk. No warranty is given or implied of the suitability 
    of this applet for any specific application. Neither Erica Sadun nor 
    Charles River Media will be held responsible for any unwanted effects 
    due to the use of this applet or any derivative. 
*/


//------------------RANDOM NUMBERS----------------------------
var js_mult1=3141
var js_mult2=5821
var js_m1=100000000
var js_m2=10000
var js_iseed=0
var js_iseed1=0
var js_iseed2=0


// Return a Random Integer between 1 and N 
// (adapted from cookbook standard 0 to N-1)
function random(n)
{
    if (js_iseed == 0)
    {
        now = new Date()
        js_iseed = now.getHours() + now.getMinutes() * 60 
                    + now.getSeconds() * 3600
    }
    js_iseed1 = js_iseed / js_m2
    js_iseed2 = js_iseed % js_m2
    var tmp = (((js_iseed2 * js_mult1 + js_iseed1 * js_mult2) % js_m2) * 
                js_m2 + (js_iseed2 * js_mult2)) % js_m1
    js_iseed = (tmp + 1) % js_m1
    return (Math.floor((js_iseed/js_m1) * n) + 1)
}

//----------------------PATH UTILITIES--------------------------
// Get the grandparent directory and append aDir
function getSibling(aDir)
{
    var loc = ""+document.location
    
    // get this dir, then parent
    var base = loc.substring(0, loc.lastIndexOf("/"))
    base = base.substring(0, base.lastIndexOf("/")+1)
    return base+aDir+'/'
}

//----------------------DICE UTILITIES--------------------------
function dice(aform)
{

    // Determine Number of Dice and Sides
    var num = aform.number.options.selectedIndex + 1
    var sides = aform.sides.options.selectedIndex + 2
    
    // Get the Dice Image Directory
    var baseRef = getSibling("GRAFX/DICE")
    
    // Frame the body
    var s1 = "<BODY BGCOLOR=\"ffffff\"><FONT SIZE=6 COLOR=\"770000\"><CENTER>"
    var s2 = "</CENTER></FONT></BODY>"
    
    // Frame the table
    var t1 = "<TABLE BORDER=1><TR>"
    var t2 = "</TABLE></TR>"
    
    // Frame the specific images
    var i1 = "<TD><IMG SRC=\""+baseRef+((sides > 9) ? "NDIE" : "DIE")
    var i2 = ".GIF\" HEIGHT=32 WIDTH=32></TD>"
    
    // Initialize dice window
    parent.JCdice.document.open()
    parent.JCdice.document.write(s1+t1)
    
    // Init counter
    var count = 0

    // Get each die    
    for (var xx=0; xx<num; xx++) {
        var yy = random(sides)
        parent.JCdice.document.write(i1+yy+i2)
        count += yy
    }
    
    // Conclude dice with the count
    parent.JCdice.document.write(
        "<TD width=32 align=center>["+count+"]</TD>"+t2+s2)
    parent.JCdice.document.close()
}

<!-- done hiding --></SCRIPT></HEAD>

<BODY bgcolor="ffffff" link="0000ff" vlink="770077">
    
    <FONT COLOR="007777"><H1><IMG SRC="../GRAFX/SPICE.JPG" WIDTH=37 HEIGHT=72
    ALIGN = LEFT>Fantasy Rollplaying Dice</H1></FONT>
    <BLOCKQUOTE><FONT COLOR="770000">
        Many Fantasy Rollplaying (FRP) systems require the
        players to cast die of varying types during the
        execution of the game.
        This script permits a player to select the number
        and sides of dice to be played.
    </FONT></BLOCKQUOTE>
    
<!-- Ugly PRE Formatting Follows -->

<FONT SIZE=4><FORM>
<CENTER>
<INPUT TYPE="BUTTON" VALUE="      Roll Dice      " 
    onClick="dice(this.form)"><p>

Number of Dice:
<SELECT    NAME="number" SIZE="1">
    <OPTION>1
    <OPTION SELECTED>2
    <OPTION>3
    <OPTION>4
    <OPTION>5
    <OPTION>6
    <OPTION>7
    <OPTION>8
</SELECT><p>

Sides of Dice
<SELECT    NAME="sides" SIZE="1">
    <OPTION>2
    <OPTION>3
    <OPTION>4
    <OPTION>5
    <OPTION SELECTED>6
    <OPTION>7
    <OPTION>8
    <OPTION>9
    <OPTION>10
    <OPTION>11
    <OPTION>12
    <OPTION>13
    <OPTION>14
    <OPTION>15
    <OPTION>16
    <OPTION>17
    <OPTION>18
    <OPTION>19
    <OPTION>20
    <OPTION>21
    <OPTION>22
    <OPTION>23
    <OPTION>24
</SELECT>
</CENTER></FORM>
    
</FONT></BLOCKQUOTE>
    
<BR><BR>
    
<FONT COLOR="007777"><H2>Discussion</H2></FONT>
<FONT SIZE=4>
Netscape needs to know the correct path to load these
graphic images. The <FONT COLOR="770000">getSibling</FONT>
function recovers the parent's path from the document
location and adds directions to a sibling or nephew
folder. It strips off the document name and then the
current directory.
</FONT>

<FONT COLOR="770000" SIZE=3><PRE>
// Get the grandparent directory and append aDir
function getSibling(aDir)
{
    var loc = ""+document.location
    
    // get this dir, then parent
    var base = loc.substring(0, loc.lastIndexOf("/"))
    base = base.substring(0, base.lastIndexOf("/")+1)
    return base+aDir+'/'
}

<h5>Copyright &copy;1996 by Charles River Media, All Rights Reserved</h5>
</BODY>
</HTML>